#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>

#define KEYDevice "/dev/input/event4"

char key_value(int code)
{
	switch(code)
	{
		case 2:
			return '1';
			
		case 3:
			return '2';
			
		case 4:
			return '3';
			
		case 5:
			return '4';
			
		case 6:
			return '5';
			
		case 7:
			return '6';
			
		case 8:
			return '7';
			
		case 9:
			return '8';
		
		case 10:
			return '9';
			
		case 1:
			return '*';
			
		case 115:
			return '0';
			
		case 114:
			return '#';
		
		default:
			return 'e';
	} 	 
}


int main(int argc,char *argv[])
{
	int keys_fd;	
 	struct input_event t;

        keys_fd = open(KEYDevice, O_RDONLY);

	if(keys_fd <= 0)
	{
                printf("open key device error!\n");
		return 0;
	}


	while(1)
	{	
                if(read(keys_fd,&t,sizeof(t)) == sizeof(t)) 
		{
		    if(t.type == EV_KEY)
			if(t.value == 0)
			{
			    printf("%c\n",key_value(t.code));
			}
		}
	}	

	close(keys_fd);
	
        return 0;
}
